import host from "./host";
export function sendApply(data, files) {
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'post',
            url: host.hostUrl + '/partner/sendapply',
            // timeout: 10,
            data: {
                values: data,
                files: files
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}

export function sendSMS(data, files) {
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'post',
            url: host.hostUrl + '/partner/sendsms',
            // timeout: 10,
            data: {
                values: data,
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}

export function doLogin(data) {
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'post',
            url: host.hostUrl + '/partner/login',
            data: {
                values: data
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}

export function InviteCode() {
    var token = api.getPrefs({
        sync: true,
        key: 'token'
    });
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'get',
            url: host.hostUrl + '/partner/invitecode',
            // timeout: 10,
            headers: {
                "authorization": 'Bearer ' + token
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}

export function TeamMembers(data) {
    var token = api.getPrefs({
        sync: true,
        key: 'token'
    });
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'get',
            url: host.hostUrl + '/partner/team',
            // timeout: 10,
            headers: {
                "authorization": 'Bearer ' + token
            },
            data: {
                values: data
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}

export function getUserInfo() {
    var token = api.getPrefs({
        sync: true,
        key: 'token'
    });
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'get',
            url: host.hostUrl + '/partner/info',
            // timeout: 10,
            headers: {
                "authorization": 'Bearer ' + token
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}

export function MainTotalData() {
    var token = api.getPrefs({
        sync: true,
        key: 'token'
    });
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'get',
            url: host.hostUrl + '/partner/alldata',
            // timeout: 10,
            headers: {
                "authorization": 'Bearer ' + token
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}

export function updateInfo(data) {
    var token = api.getPrefs({
        sync: true,
        key: 'token'
    });
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'post',
            url: host.hostUrl + '/partner/updateinfo',
            headers: {
                "authorization": 'Bearer ' + token
            },
            data: {
                values: data
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}


export function changepass(data) {
    var token = api.getPrefs({
        sync: true,
        key: 'token'
    });
    return new Promise(function (resolve, reject) {
        api.ajax({
            method: 'post',
            url: host.hostUrl + '/partner/changepass',
            headers: {
                "authorization": 'Bearer ' + token
            },
            data: {
                values: data
            }
        }, function (ret, err) {
            if (err) {
                reject(err)
            } else {
                resolve(ret);
            }
        })
    });
}